const koa = require('koa');
const fs = require('fs');
const path = require('path');
const app = new koa();

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  ctx.set('X-Response-Time', `${ms}ms`);
});

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  console.log(`${ctx.method} ${ctx.url} - ${ms}`);
});

app.use(async ctx => {
  ctx.body = 'hello world';
});

// 加注释
app.listen(3001, err => {
  if (err) return console.log(err);
  console.log('开始监听3001端口');
});